import request from '@/utils/request'
import { AxiosPromise } from 'axios'

// apiUrl 流程定义(实例)
const api = {
	listCategory: '/v1/process/list-category?keyword=', // 获取所有分类流程定义列表
	updateStateId: '/v1/process/update-state', // 根据流程定义ID更新流程状态
	updateProcessSort: '/v1/process/sort', // 流程组排序
	delete: '/v1/process/delete', // 根据流程定义ID删除流程定义相关信息
	create: '/v1/process/create', // 创建添加
	get: '/v1/process/get', // 查询Id信息
	clone: '/v1/process/clone' // 查询 id 克隆流程定义信息
}

function flowDefinitionListCategoryApi(data: any): AxiosPromise {
	const keyword = data.keyword
	return request({
		url: api.listCategory + (keyword ? keyword : ''),
		method: 'post',
		data,
		headers: {
			'Menu-code': 'PROCESS'
		}
	})
}

function flowDefinitionUpdateStateIdApi(data: any): AxiosPromise {
	return request({
		url: `${api.updateStateId}-${data.id}`,
		method: 'post',
		headers: {
			'Menu-code': 'PROCESS'
		}
	})
}

function updateProcessSortApi(data: any): AxiosPromise {
	return request({
		url: api.updateProcessSort,
		method: 'post',
		data,
		headers: {
			'Menu-code': 'PROCESS'
		}
	})
}

function flowDefinitionUpdateSortIdApi(data: any): AxiosPromise {
	return request({
		url: `${api.updateStateId}-${data.id}`,
		method: 'post'
	})
}
function flowDefinitionDeleteApi(data: any): AxiosPromise {
	return request({
		url: api.delete,
		method: 'post',
		data,
		headers: {
			'Menu-code': 'PROCESS'
		}
	})
}

function flowDefinitionCreateApi(data: any): AxiosPromise {
	return request({
		url: api.create,
		method: 'post',
		data,
		headers: {
			'Menu-code': 'PROCESS'
		}
	})
}

function flowDefinitionGetApi(data: any): AxiosPromise {
	return request({
		url: api.get,
		method: 'post',
		data,
		headers: {
			'Menu-code': 'PROCESS'
		}
	})
}

function flowDefinitionCloneApi(data: any): AxiosPromise {
	return request({
		url: api.get,
		method: 'post',
		data
	})
}

export default {
	flowDefinitionListCategoryApi,
	flowDefinitionUpdateStateIdApi,
	updateProcessSortApi,
	flowDefinitionUpdateSortIdApi,
	flowDefinitionDeleteApi,
	flowDefinitionCreateApi,
	flowDefinitionGetApi,
	flowDefinitionCloneApi
}
